package com.itheima.mall.web.ums;


import com.itheima.mall.commons.result.Result;
import com.itheima.mall.dubbo.api.ums.ResourceCategoryImplService;
import com.itheima.mall.dubbo.api.ums.ResourceCategoryService;
import com.itheima.mall.dubbo.api.ums.ResourceService;
import com.itheima.mall.entity.domain.ums.ResourceCategory;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 资源分类表 前端控制器
 * </p>
 *
 * @author qinglang
 * @since 2022-07-05
 */
@RestController
@RequestMapping("/resourceCategory")
@CrossOrigin(origins = "*")
public class ResourceCategoryController {

    @DubboReference
    private ResourceCategoryService resourceCategoryService;

    /**
     * 添加后台资源分类
     *
     * @param resourceCategory
     * @return
     */
    @PostMapping("/create")
    public Result creat(@RequestBody ResourceCategory resourceCategory) {
        resourceCategoryService.creat(resourceCategory);
        return Result.success();
    }

    /**
     * 根据ID删除后台资源
     *
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        resourceCategoryService.delete(id);
        return Result.success();
    }

    /**
     * 查询所有后台资源分类
     * @return
     */
    @GetMapping("/listAll")
    public Result listAll() {
        List<ResourceCategory> resourceCategories = resourceCategoryService.listAll();
        return Result.success(resourceCategories);
    }

    /**
     * 修改后台资源分类
     * @param id
     * @param resourceCategory
     * @return
     */
    @PostMapping("/update/{id}")
    public Result update(@PathVariable Integer id, @RequestBody ResourceCategory resourceCategory){
        resourceCategoryService.updateRC(resourceCategory);
        return Result.success();
    }

}

